<?php include '../header.php'; ?>
<?php include '../connect.php'; 
	  include 'function.php';?>
<script type="text/javascript">
	//<![CDATA[
	$(document).ready(function(){
	
		$(".delete_user").click(function(){
			alpha = $(this);
			alert( "Name: "+$(this).attr("alt") );
			$.ajax({
			   data: "username="+$(this).attr("alt"),
			   url: "delete_user.php",
			   success: function(msg){
			   	$(alpha).parents().filter('tr').hide('fast');
			   }
			});
		}); 
		
		$("#modif_user").hide();
		$(".muser").click(function(){
			var html = $.ajax({ data: "onlyname=1&username="+$(this).attr("alt"), url: "modif_user.php", async: false }).responseText;
			$("#modif_user").html(html);
			$("#modif_user").children("h4").html("Utilisateur: "+$(this).attr("alt"));
			$("#modif_user").slideToggle('slow');
			
		});
		
	});
		
	
		
	
	//]]>
</script>
	  <div id="teaser">
	  </div>


	  <div id="main">


			<div id="gauche">
				<div class="nothing">
					<?php include '../sidebar.php'; ?>
				</div>
			</div>
			<?php

			if ( isset($_SESSION['auth'] ))
			{
			
			$sql = "SELECT categ FROM $table_name WHERE user_name='$_SESSION[logname]'";
			$result = mysql_query($sql,$db);
			$infos = mysql_fetch_array($result);

			if ( $infos['categ'] != 10 )
			{
			?>
			<h3>Acc&egrave;s interdit</h3>
				<p>Vous n'avez pas l'autorisation d'acc&eacute;der &agrave; cette page.</p>
				<?php //pensez a ajouter la redirection vers la page d'accueil ?>
			<?php	
			}
			else 
			{
			?>	
			<div id="droite">
			<div class="nothing">
				<div class="subcolumns">
					<div class="c25l">
						<div class="subcl">
							<div class="ylert">
								<strong>Statistiques</strong>
								<p>Nombre total d'utilisateur: <?php echo opencv_allmember(); ?>
								<br />
								Utilisateurs en recherche: <?php echo opencv_allmember(still_looking); ?></p>
							</div>

						</div>
					</div>

					<div class="c75r">
					
						<div class="subcr bgwhite bdg topbdg">
							<h3>Espace administrateur</h3>
							<h4>Modifier utilisateur:</h4>
							<?php
								$nbbypage = 5;
								
								if(!isset($_GET['page'])){$page=1;$current= 0;}
								else {$page = $_GET['page'];
								
								$current = $page * $nbbypage;}
								
								
								
								$sql = "SELECT * FROM $table_name ORDER BY create_date DESC LIMIT $current,$nbbypage ";
								$result = mysql_query($sql,$db)
									  or die("Exécution requête 1 impossible".mysql_error()); 				
							?>
								<table id="job-posts" class="job-posts" cellspacing="0" style="width:100%;">
									<?php
									$i=1;
									while($user = mysql_fetch_array($result))
									{?>				
									<tr>

										<td>
											<img class="imguser" src="../images/user_
											<?php switch($i)
												{
												case 1: echo "gray";break;
												case 2: echo "red";break;
												case 3: echo "green";break;	
												case 4: echo "orange";break;
												case 5: echo "suit";break;	
												case 6: echo "gray";break;
												case 7: echo "red";break;
												case 8: echo "green";break;	
												case 9: echo "orange";break;
												case 10: echo "suit";break;						
												}
											?>
											.png" />
											<a href="<?php echo $_GLOBALS['site_url']."../user/".$user['user_name'];?>" title="<?php echo $user['title']; ?>"><?php echo $user['user_name']; ?></a> 
											<span>| Enregistr&eacute; le: <?php echo $user['create_date']; ?> | Derni&egrave;re modification le: <?php echo $user['last_update']; ?></span>
										</td>
										<td>
											<?php
												if(stillLooking($user['user_name'])==0){
													echo "<img src='../img/flag_red.gif' title='Ne cherche plus'/>";
												}
												else
												{
													echo "<img src='../img/flag_green.gif' title='Recherche'/>";
												}
											?></td>
										<td class="txtright">
											
											<span alt="<?php echo $user['user_name']; ?>" class="muser"><img src="../images/edit.png" class="imgcancel" alt="edit" /></span> 
											<a href="#" title="delete" alt="<?php echo $user['user_name']; ?>" class="delete_user"><img src="../images/cancel.png" class="imgcancel" alt="delete" /></a>
										</td>
									</tr>
									<?php 
										$i++;
									} ?>
								</table>
							<?php


							$result = mysql_query($sql,$db)
								or die("Exécution requête 1 impossible".mysql_error()); 
							$nomb = mysql_fetch_array($result);
							?>
						</div>
						<div id="modif_user" class="subcolumns bdg bgwhite ">

						</div>
						<div id="nav_page">
							<?php
							$prec = $page;
							$actually = $prec*$nbbypage;
							$suiv = $page + 1;
							 if($page != 1){echo "<a href=".$_GLOBALS['site_url']."admin/index.php?page=".$prec." >Prev |</a>";}
							 if($actually <= opencv_allmember()){echo "<a href=".$_GLOBALS['site_url']."admin/index.php?page=".$suiv." > Next</a>";} ?>
							
						</div>
						
					</div>
				</div>
				
			</div>
			
			<?php
			}
			?>
			<?php }	?>
			</div>
			</div>


<?php include '../footer.php'; ?>			